package com.shangxia.dreaming.start;

import com.shangxia.dreaming.business.StartJob;
import com.shangxia.dreaming.common.content.ConditionContent;
import lombok.extern.slf4j.Slf4j;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @ProjectName: dreaming
 * @ClassName: MyCommandLineRunner
 * @Time: 2020/10/6
 * @Author: zhouy
 * @Description:
 * @Experience:
 */

@Slf4j
@Component
public class MyCommandLineRunner implements CommandLineRunner {

    @Resource
    private StartJob startJob;

    @Override
    public void run(String... args) throws Exception {
        Long startTime = System.currentTimeMillis();
        if (ConditionContent.TYPE.contains("-")){
            ConditionContent.SUM_CODE_LENGTH = Integer.parseInt(ConditionContent.TYPE.split("-")[0]);
            ConditionContent.SON_CODE_LENGTH = Integer.parseInt(ConditionContent.TYPE.split("-")[1]);
            ConditionContent.SON_CHECK_CODE_LENGTH = Integer.parseInt(ConditionContent.TYPE.split("-")[2]);
            if (ConditionContent.TYPE.length() == 10) {
                ConditionContent.SON_INDEX1 = Integer.parseInt(ConditionContent.TYPE.split("-")[3]);
                ConditionContent.SON_INDEX2 = Integer.parseInt(ConditionContent.TYPE.split("-")[4]);
            }
        }
        startJob.doWork(ConditionContent.TYPE);
        log.info("程序耗时：" + (System.currentTimeMillis() - startTime) / 1000 + "s");
        Thread.sleep(2000);
        System.exit(0);
    }
}
